const app = getApp();
Page({

    data: {
        tabIdx: 0,
        banners: [],
        list: [],
        before: []
    },
    onLoad: function (options) {
        wx.getSystemInfo({
            success: (res) => {
                this.setData({
                    height: (((res.windowHeight - 238) * 750) / res.windowWidth)
                })
            }
        })

        this.getBanner()
        this.getList();
    },
    toMore() {
      wx.navigateTo({
        url: '/pages/chat-history/history',
      })
    },
    getBanner() {
        app.http.$ajax({
            url: 'v1.chat/banners',
            loading: false
        }, {
            success: (res) => {
                this.setData({
                    banners: app.processImg(res.data.data, 'imageurl')
                })
            }
        });
    },
    getList() {
        app.http.$ajax({
            url: 'v1.chat/history',
            loading: '获取直播数据...'
        }, {
            success: (res) => {
                this.setData({
                    list: app.processImg(res.data.data)
                })
            }
        })
    },
    handleTab(e) {
        let idx = e.currentTarget.dataset.idx;
        if(idx == 1) { //直播预告
            this.getBefore()
        }
        this.setData({
            tabIdx: e.currentTarget.dataset.idx
        })
    },
    getBefore() {
        app.http.$ajax({
            url: 'v1.chat/getBefore'
        }, {
            success: (res) => {
                this.setData({
                    before: res.data
                })
            }
        })
    },
    open(e) {
        let course_id = e.currentTarget.dataset.id;
        wx.navigateTo({
          url: '/pages/lesson-detail/lesson-detail?course_id=' + course_id,
        })
      
    },
    chat(e) {
      let start_time = e.currentTarget.dataset.start_time;
      let id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/advance/advance?id=' + id + '&start_time=' + start_time,
      })
    }
})